package com.pi.tools;

import java.util.HashMap;
import java.util.ResourceBundle;

import com.mapdigit.gis.geometry.GeoLatLng;

public abstract class GMapUtils {
	protected final int CARS_LENGTH = 60;// 车辆位置信息的固定长度
	protected final String BUNDLE_NAME = "ApplicationResources"; //$NON-NLS-1$
	protected final ResourceBundle RESOURCE_BUNDLE =null; 
	protected String chinamapoffset="chinamapoffset";
	protected LocalChinaMapOffset chinaMapOffset = LocalChinaMapOffset.getInstance(chinamapoffset);
	protected GeoLatLng earth = null;
	protected static  HashMap<String,String> hashMapState;;
	
	public GMapUtils(){
//		chinamapoffset = getString("chinamapoffset");
		chinamapoffset =  "chinamapoffset";
		if(hashMapState == null){
			hashMapState = new HashMap<String,String>();
			hashMapState.put("gmap.gap.lat", "-0.00266723400879");
			hashMapState.put("gmap.gap.lng", "0.0052947138672");
			hashMapState.put("car.carstat100", "西经");
			hashMapState.put("car.carstat101", "东经");
			hashMapState.put("car.carstat110", "南纬");
			hashMapState.put("car.carstat111", "北纬");
			hashMapState.put("car.carstat120", "");
			hashMapState.put("car.carstat121", "紧急报警");
			hashMapState.put("car.carstat130", "油路正常");
			hashMapState.put("car.carstat131", "油路断开");
			hashMapState.put("car.carstat140", "");
			hashMapState.put("car.carstat141", "超速报警");
			hashMapState.put("car.carstat150", "");
			hashMapState.put("car.carstat151", "振动报警");
			hashMapState.put("car.carstat160", "主电源正常");
			hashMapState.put("car.carstat170", "");
			hashMapState.put("car.carstat171", "");
			hashMapState.put("car.carstat200", "刹车正常");
			hashMapState.put("car.carstat201", "刹车制动");
			hashMapState.put("car.carstat210", "车门关闭");
			hashMapState.put("car.carstat211", "车门打开");
			hashMapState.put("car.carstat220", "左转向灯关闭");
			hashMapState.put("car.carstat221", "左转向灯打开");
			hashMapState.put("car.carstat230", "右转向灯关闭");
			hashMapState.put("car.carstat231", "右转向灯打开");
			hashMapState.put("car.carstat240", "远光灯关闭");
			hashMapState.put("car.carstat241", "远光灯打开");
			hashMapState.put("car.carstat250", "ACC关闭");
			hashMapState.put("car.carstat251", "ACC打开");
			hashMapState.put("car.carstat260", "");
			hashMapState.put("car.carstat261", "");
			hashMapState.put("car.carstat270", "");
			hashMapState.put("car.carstat271", "");
			hashMapState.put("car.carstat300", "卫星定位未锁定");
			hashMapState.put("car.carstat301", "卫星定位锁定");
			hashMapState.put("car.carstat310", "卫星定位天线正常");
			hashMapState.put("car.carstat311", "卫星定位天线短路");
			hashMapState.put("car.carstat320", "卫星定位天线正常");
			hashMapState.put("car.carstat331", "定位模块异常");
			hashMapState.put("car.carstat340", "通信模块正常");
			hashMapState.put("car.carstat341", "通信模块异常");
			hashMapState.put("car.carstat350", "");
			hashMapState.put("car.carstat351", "出区域越界");
			hashMapState.put("car.carstat360", "");
			hashMapState.put("car.carstat361", "入区域越界");
			hashMapState.put("car.carstat370", "");
			hashMapState.put("car.carstat371", "");
			hashMapState.put("car.carstat400", "备用电池正常");
			hashMapState.put("car.carstat401", "备用电池异常");
			hashMapState.put("car.carstat410", "地理栅栏正常");
			hashMapState.put("car.carstat411", "地理栅栏越界");
			hashMapState.put("car.carstat420", "发动机关闭");
			hashMapState.put("car.carstat421", "发动机打开");
			hashMapState.put("car.carstat430", "");
			hashMapState.put("car.carstat431", "疲劳驾驶报警");
			hashMapState.put("car.carstat440", "");
			hashMapState.put("car.carstat441", "");
			hashMapState.put("car.carstat450", "");
			hashMapState.put("car.carstat460", "");
			hashMapState.put("car.carstat461", "");
			hashMapState.put("car.carstat470", "");
			hashMapState.put("car.carstat471", "");
		}
		
	}
	
	public String getString(String key) {
		String dest = key;
		try {
			dest = RESOURCE_BUNDLE.getString(key);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dest;
	}
	
	/**
	 * 获取时间
	 */
	public abstract String getTime(String str);
	/**
	 * 获取经度
	 * @param str
	 * @return
	 */
	public abstract Double getlongitude(String str);
	/**
	 * 获取纬度
	 * @param str
	 * @return
	 */
	public abstract Double getLatitude(String str);
	/**
	 * 获取速度
	 * @param str
	 * @return
	 */
	public abstract Double getSpeed(String str);
	/**
	 * 获取方向
	 * @param str
	 * @return
	 */
	public abstract String getDirection(String str);
	/**
	 * 获取方向
	 * @param str
	 * @return
	 */
	public abstract Integer getDirectNotChage(String str);
	/**
	 * 获取高度
	 * @param str
	 * @return
	 */
	public abstract Double getHeight(String str);
	/**
	 * 获取里程
	 * @param str
	 * @return
	 */
    public abstract Double getMileage(String str);
    /**
     * 获取状态
     * @param str
     * @return
     */
    public abstract String getState(String str);
    
    /*
	 * 把16进制字符串转换成字节数组
	 * 
	 * @param hex
	 * 
	 * @return
	 */
	public byte[] hexStringToByte(String hex) {
		int len = (hex.length() / 2);
		byte[] result = new byte[len];
		char[] achar = hex.toCharArray();
		for (int i = 0; i < len; i++) {
			int pos = i * 2;
			result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
		}
		return result;
	}

	private  byte toByte(char c) {
		byte b = (byte) "0123456789ABCDEF".indexOf(c);
		return b;
	}
	
	public String hexToString(String dest) {
		StringBuffer append = new StringBuffer();
		int length = dest.length() / 2;
		for (int i = 0; i < length; i++) {
			String destx = dest.substring(i * 2, 2 * (i + 1));
			append.append(Integer.parseInt(destx, 16));
		}
		return append.toString();
	}
}
